// 提交链接：https://leetcode.cn/problems/maximize-number-of-subsequences-in-a-string/description/
// lc2207. 字符串中最多数目的子序列
// 完成日期：2024/9/24
// c++ 前缀和 贪心

class Solution {
public:
    long long maximumSubsequenceCount(string text, string pattern) {
        int x = 0, y = 0;
        long long ans = 0;
        for(auto& k : text)
        {
            if(k == pattern[1])
            {
                y++;
                ans += x;
            }
            if(k == pattern[0])
                x++;
        }
        return ans += max(x,y);
    }
};